// import { ElStep } from 'element-plus';
import { createRouter, createWebHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue'

const router = createRouter({
    history: createWebHistory(
        import.meta.env.BASE_URL),
    routes: [
        // 一级404路由
        {
            path: "/:id(.*)",
            component: () =>
                import ("../views/NotFound.vue"),
        },
        // 一级路由重定向
        {
            path: "/",
            redirect: "/index/home"
        },
        {
            path: "/index",
            name: "index",
            component: () =>
                import ("../views/Index.vue"),
            children: [
                // 用户管理路由
                {
                    path: "/index/home",
                    name: "home",
                    component: () =>
                        import ("../views/Index/Home.vue"),

                },
                //用户管理
                {
                    path: "/index/manager",
                    name: "manager",
                    component: () =>
                        import ("../views/Index/Manager.vue"),
                },
                //图表路由（用户）
                {
                    path: "/index/echars",
                    name: 'img',
                    component: () =>
                        import ("../views/Index/Echars.vue")
                },
                // 商品路由勿动
                {
                    path: "/index/goods",
                    name: "goods",
                    meta: { title: '商品管理页面' },
                    component: () =>
                        import ("../views/Index/Goods.vue"),
                    children: []
                },
                {
                    path: "/index/shopgroup",
                    name: "shopgroup",
                    meta: { title: '商品分类管理页面' },
                    component: () =>
                        import ("../views/Index/Goods/ShopGroup.vue"),
                },
                {
                    path: "/index/goodsadd",
                    name: "goodsadd",
                    meta: { title: '商品新增页面' },
                    component: () =>
                        import ("../views/Index/Goods/GoodsAdd.vue"),
                },
                {
                    path: "/index/goodsedit",
                    name: "goodsedit",
                    meta: { title: '商品编辑页面' },
                    component: () =>
                        import ("../views/Index/Goods/GoodsEdit.vue"),
                },
                {
                    path: "/index/order",
                    name: "order",
                    component: () =>
                        import ("../views/Index/Order.vue"),
                },
                {
                    path: "/index/address",
                    name: "address",
                    component: () =>
                        import ("../views/Index/Address.vue"),
                },
                {
                    path: "/index/addressedit",
                    name: "addressedit",
                    component: () =>
                        import ("../views/Index/AddressEdit.vue"),
                },
                // 库存-总览
                {
                    path: "/index/stock",
                    name: "stock",
                    component: () =>
                        import ("../views/Index/Stock.vue"),
                },
                // 库存-搜索页面
                {
                    path: "/index/mo-search",
                    name: 'mo-search',
                    component: () =>
                        import ('../views/Index/gbg/search.vue'),
                },

                //库存-新增商品库存管理
                {
                    path: "/index/addmounted",
                    name: "addmounted",
                    component: () =>
                        import ("../views/Index/gbg/addMounted.vue"),
                },
                //库存- 编辑页面
                {
                    path: '/index/amend',
                    name: 'ament',
                    component: () =>
                        import ('../views/Index/gbg/amend.vue')
                },
                // 测试页面
                {
                    path: '/index/test',
                    name: 'test',
                    component: () =>
                        import ('../views/Index/gbg/test.vue')
                },
                // 急需补货提示页面
                {
                    path: '/index/hint',
                    name: 'hint',
                    component: () =>
                        import ('../views/Index/gbg/hint.vue')
                },
                {
                    path: '/index/orderlist',
                    name: 'orderlist',
                    component: () =>
                        import ('../views/Index/Order/orderlist.vue')
                },
                {
                    path: '/index/editorder',
                    name: 'editorder',
                    component: () =>
                        import ('../views/Index/Order/editorder.vue')
                },
                {
                    path: '/index/search',
                    name: 'search',
                    component: () =>
                        import ('../views/Index/Order/searchorder.vue')
                },
                {
                    path: "/index/person",
                    name: "person",
                    component: () =>
                        import ("../views/Index/Person.vue"),
                },
                {
                    path: '/index/addInfo',
                    name: 'addInfo',
                    component: () =>
                        import ("../views/Index/addInfo.vue")
                },
                {
                    path: '/index/editInfo',
                    name: 'editInfo',
                    component: () =>
                        import ("../views/Index/editInfo.vue")
                },
                {
                    path: '/index/order/search',
                    name: 'search',
                    component: () =>
                        import ('../views/Index/Order/searchorder.vue')
                },
                {
                    path: '/index/shuju',
                    name: 'shuju',
                    component: () =>
                        import ('../views/Index/Order/shuju.vue')
                },
            ]
        },
        // 登录路由

        {
            path: "/login",
            name: "login",
            meta: { title: "登录" },
            component: () =>
                import ("../views/Login.vue"),
        },
        // 注册路由
        {
            path: "/register",
            name: "/register",
            meta: { title: "注册" },
            component: () =>
                import ("../views/Register.vue"),
        }

    ]
});

router.beforeEach((to, from, next) => {
    var token = localStorage.getItem("token");
    if (to.path == '/register') {
        next();
    } else {
        if (to.path == '/login') {
            if (token) {
                next("/");
            } else {
                next();
            }
        } else {
            if (token) {
                next();
            } else {
                next('/login')
            }
        }
    }
});
// router.beforeEach((to, from, next) => {
//   if (to.path == "/register")
// })

export default router